package com.cauli.search.controller;

import cn.hutool.core.bean.BeanUtil;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.cauli.search.model.dto.FileSearchDTO;
import com.cauli.search.model.dto.SearchFileQueryDTO;
import com.cauli.search.model.vo.SearchFileVO;
import com.cauli.search.service.ElasticsearchService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.qiwenshare.common.anno.MyLog;
import com.qiwenshare.common.result.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * @author Cauli
 * @date 2023-03-18 12:00
 * @description 文件操作 前端控制器
 */

/**
 * @author Cauli
 * @date 2023/9/2 19:44
 * @description 文件搜索 前端控制器
 */
@Api(tags = "文件搜索")
@ApiSort(1)
@RestController
@RequestMapping("/search")
public class ElasticsearchController {
    @Autowired
    private ElasticsearchService elasticService;

    public static final String CURRENT_MODULE = "文件搜索";


    @MyLog(operation = "搜索文件", module = CURRENT_MODULE)
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "搜索文件")
    @GetMapping(value = "/searchFile")
    public RestResult<SearchFileVO> searchFile(SearchFileQueryDTO searchFileQueryDTO) {
        List<SearchFileVO> searchFileVOList = elasticService.searchES(searchFileQueryDTO);
        return RestResult.success().dataList(searchFileVOList, searchFileVOList.size());

    }
}
